package com.legal.aid.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.legal.aid.common.annotation.Log;
import com.legal.aid.common.core.controller.BaseController;
import com.legal.aid.common.core.domain.AjaxResult;
import com.legal.aid.common.enums.BusinessType;
import com.legal.aid.system.domain.Case;
import com.legal.aid.system.service.ICaseService;
import com.legal.aid.common.utils.poi.ExcelUtil;
import com.legal.aid.common.core.page.TableDataInfo;

/**
 * 经典案例Controller
 * 
 * @author ruoyi
 * @date 2025-05-27
 */
@RestController
@RequestMapping("/system/case")
public class CaseController extends BaseController
{
    @Autowired
    private ICaseService zCaseService;

    /**
     * 查询经典案例列表
     */
    @PreAuthorize("@ss.hasPermi('system:case:list')")
    @GetMapping("/list")
    public TableDataInfo list(Case zCase)
    {
        startPage();
        List<Case> list = zCaseService.selectZCaseList(zCase);
        return getDataTable(list);
    }

    /**
     * 导出经典案例列表
     */
    @PreAuthorize("@ss.hasPermi('system:case:export')")
    @Log(title = "经典案例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Case zCase)
    {
        List<Case> list = zCaseService.selectZCaseList(zCase);
        ExcelUtil<Case> util = new ExcelUtil<Case>(Case.class);
        util.exportExcel(response, list, "经典案例数据");
    }

    /**
     * 获取经典案例详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:case:query')")
    @GetMapping(value = "/{caseId}")
    public AjaxResult getInfo(@PathVariable("caseId") Long caseId)
    {
        return success(zCaseService.selectZCaseByCaseId(caseId));
    }

    /**
     * 新增经典案例
     */
    @PreAuthorize("@ss.hasPermi('system:case:add')")
    @Log(title = "经典案例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Case zCase)
    {
        return toAjax(zCaseService.insertZCase(zCase));
    }

    /**
     * 修改经典案例
     */
    @PreAuthorize("@ss.hasPermi('system:case:edit')")
    @Log(title = "经典案例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Case zCase)
    {
        return toAjax(zCaseService.updateZCase(zCase));
    }

    /**
     * 删除经典案例
     */
    @PreAuthorize("@ss.hasPermi('system:case:remove')")
    @Log(title = "经典案例", businessType = BusinessType.DELETE)
	@DeleteMapping("/{caseIds}")
    public AjaxResult remove(@PathVariable Long[] caseIds)
    {
        return toAjax(zCaseService.deleteZCaseByCaseIds(caseIds));
    }
}
